home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.06 Jun 88 / icon source / TestMenus.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-03-28  |  2.0 KB  |  100 lines  |  [TEXT/EDIT]

  1. {$L TestMenus/Rsrc }
  2.  
  3. program TestMenus;
  4.  
  5. uses
  6.     Macintf, StdPoll, StdMenu, IconMenu;
  7.     
  8. const
  9.     { Menu IDs }
  10.     AppleMenuID = 256;
  11.         AboutAlertID = 1000;
  12.     FileMenuID = 257;
  13.     EditMenuID = 258;
  14.     CktMenuID = 259; { not a resource id }
  15.         FirstCktIcon = 500;
  16.         NumCktIcons = 7;
  17.         IconsWide = 3;
  18.         BfSpace = 3;
  19.     
  20. var
  21.     { Instances of Menu Handlers }
  22.     AppleMenu : AppleMenuHdlr;
  23.     FileMenu : StdFileMenuHdlr;
  24.     EditMenu : StdEditMenuHdlr;
  25.     CktMenu : IconMenuHdlr;
  26.  
  27.     { Event polling variables }
  28.     TheEvent : EventRecord;
  29.     EventIsForMe : Boolean;
  30.     
  31.  
  32. {
  33. |    DoMenuChoice - do a menu selection
  34. }
  35. procedure DoMenuChoice (MenuCode : LongInt);
  36. begin 
  37.     case HiWord(MenuCode) of
  38.         AppleMenuID : AppleMenu.Choose (LoWord(MenuCode));
  39.         FileMenuID : FileMenu.Choose (LoWord(MenuCode));
  40.         EditMenuID : EditMenu.Choose (LoWord(MenuCode));
  41.         CktMenuID : CktMenu.Choose (LoWord(MenuCode)) end;
  42.     HiliteMenu (0) end;
  43.  
  44. {
  45. |    PollEvent - check the event queue and dispatch event, if any
  46. }
  47. procedure PollEvent;
  48. var
  49.     TempWindow : WindowPtr;
  50. begin 
  51.     EventIsForMe := GetNextEvent(everyEvent,TheEvent);
  52.     if EventIsForMe 
  53.     then case TheEvent.what of 
  54.         mouseDown : case FindWindow (TheEvent.where,TempWindow) of
  55.             inMenuBar : DoMenuChoice(MenuSelect(TheEvent.where));
  56.             inSysWindow : SystemClick (TheEvent, TempWindow);
  57.             otherwise { ignore } end;
  58.         keyDown : if BitAnd(TheEvent.modifiers,CmdKey) <> 0
  59.             then DoMenuChoice(MenuKey(
  60.                 CHR(BitAnd(TheEvent.message,CharCodeMask))));
  61.     otherwise { ignore } end end;
  62.  
  63.  
  64. {
  65. |    InitApplication
  66. }
  67. procedure InitApplication;
  68. begin
  69.     Done := False;
  70.  
  71.     { Create the menus }
  72.     New (AppleMenu); 
  73.     AppleMenu.Setup (AboutAlertID);
  74.     AppleMenu.Create (AppleMenuID);
  75.     
  76.     New (FileMenu);
  77.     FileMenu.Create (FileMenuID);
  78.     
  79.     New (EditMenu);
  80.     EditMenu.Create (EditMenuID);
  81.     
  82.     New (CktMenu);
  83.     CktMenu.Setup (FirstCktIcon, NumCktIcons, IconsWide, 
  84.             BfSpace, 'Model');
  85.     CktMenu.Create (CktMenuID);
  86.     
  87.     DrawMenuBar;
  88.  
  89.     InitCursor end;
  90.     
  91. {
  92. |    Main
  93. }
  94. begin
  95.   InitTheMac;
  96.   InitApplication;
  97.   repeat
  98.       SystemTask;
  99.     PollEvent;
  100.       until done end.